package com.ujs.edu.medicine.dao;

import com.ujs.edu.medicine.dataobject.YunjiayiOrder;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
@Mapper
public interface YunjiayiOrderMapper {
    @Delete({
        "delete from yunjiayi_order",
        "where orderId = #{orderid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer orderid);

    /*通过UID删除*/
    @Delete({
            "delete from yunjiayi_order",
            "where userId = #{userId,jdbcType=INTEGER}"
    })
    int deleteByUID(Integer userId);

    @Insert({
        "insert into yunjiayi_order (orderId, userId, ",
        "medicineID, allPrice, ",
        "orderStatus, createtime, ",
        "shopId)",
        "values (#{orderid,jdbcType=INTEGER}, #{userid,jdbcType=INTEGER}, ",
        "#{medicineid,jdbcType=CHAR}, #{allprice,jdbcType=DECIMAL}, ",
        "#{orderstatus,jdbcType=VARCHAR}, now(), ",
        "#{shopid,jdbcType=INTEGER})"
    })
    @Options(useGeneratedKeys=true, keyProperty="orderid", keyColumn="orderId")
    int insert(YunjiayiOrder record);

    @Select({
        "select",
        "orderId, userId, medicineID, allPrice, orderStatus, createtime, shopId",
        "from yunjiayi_order",
        "where orderId = #{orderid,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="orderId", property="orderid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="userId", property="userid", jdbcType=JdbcType.INTEGER),
        @Result(column="medicineID", property="medicineid", jdbcType=JdbcType.CHAR),
        @Result(column="allPrice", property="allprice", jdbcType=JdbcType.DECIMAL),
        @Result(column="orderStatus", property="orderstatus", jdbcType=JdbcType.VARCHAR),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="shopId", property="shopid", jdbcType=JdbcType.INTEGER)
    })
    YunjiayiOrder selectByPrimaryKey(Integer orderid);

    @Select({
        "select",
        "orderId, userId, medicineID, allPrice, orderStatus, createtime, shopId",
        "from yunjiayi_order"
    })
    @Results(id = "orderMap",value = {
        @Result(column="orderId", property="orderid", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="userId", property="userid", jdbcType=JdbcType.INTEGER),
        @Result(column="medicineID", property="medicineid", jdbcType=JdbcType.CHAR),
        @Result(column="allPrice", property="allprice", jdbcType=JdbcType.DECIMAL),
        @Result(column="orderStatus", property="orderstatus", jdbcType=JdbcType.VARCHAR),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="shopId", property="shopid", jdbcType=JdbcType.INTEGER)
    })
    List<YunjiayiOrder> selectAll();

    /*通过userId查询订单*/
    @Select("select * from yunjiayi_order where userId=#{userId}")
    @ResultMap("orderMap")
    List<YunjiayiOrder> selectByUserId(@Param("userId")Integer userId);

    @Select("select * from yunjiayi_order where shopId=#{shopId}")
    @ResultMap("orderMap")
    List<YunjiayiOrder> selectByShopId(@Param("shopId")Integer shopId);

    @Update({
        "update yunjiayi_order",
        "set userId = #{userid,jdbcType=INTEGER},",
          "medicineID = #{medicineid,jdbcType=CHAR},",
          "allPrice = #{allprice,jdbcType=DECIMAL},",
          "orderStatus = #{orderstatus,jdbcType=VARCHAR},",
          "createtime = now(),",
          "shopId = #{shopid,jdbcType=INTEGER}",
        "where orderId = #{orderid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(YunjiayiOrder record);
}